﻿//using System;
//using System.Collections.Generic;
//using System.Configuration;
//using System.IO;
//using System.Linq;
//using System.Net;
//using System.Net.Mail;
//using System.Runtime.InteropServices;
//using System.Runtime.Serialization;
//using System.ServiceModel.Channels;
//using System.ServiceModel.Description;
//using System.ServiceModel.Dispatcher;
//using System.Text;
//using System.Threading.Tasks;
//using System.Web;
//using System.Xml;

//namespace WebChatApi.Common
//{
//    //    public class DateTimeContractBehaviorAttribute : Attribute, IContractBehavior
//    //    {
//    //        public const string DefaultDateTimeFormat = "yyyy-MM-dd HH;mm:ss.fff";

//    //        #region Property

//    //        /// <summary>
//    //        /// Gets or sets the date time format.
//    //        /// </summary>
//    //        /// <value>
//    //        /// The date time format.
//    //        /// </value>
//    //        public string DateTimeFormat
//    //        {
//    //            get;
//    //            set;
//    //        }

//    //        #endregion

//    //        #region Constructor

//    //        /// <summary>
//    //        /// Initializes a new instance of the <see cref="DateTimeContractBehaviorAttribute"/> class.
//    //        /// </summary>
//    //        public DateTimeContractBehaviorAttribute()
//    //            : base()
//    //        {
//    //        }

//    //        #endregion


//    //    }


//    public class CustomDataContractSerializerOperationBehavior : DataContractSerializerOperationBehavior
//    {
//        /// <summary>
//        /// Initializes a new instance of the <see cref="CustomDataContractSerializerOperationBehavior"/> class.
//        /// </summary>
//        /// <param name="operationDescription">The operation description.</param>
//        public CustomDataContractSerializerOperationBehavior(OperationDescription operationDescription)
//            : base(operationDescription) { }

//        public override XmlObjectSerializer CreateSerializer(Type type, string name, string ns, IList<Type> knownTypes)
//        {
//            var dictionary = new XmlDictionary(2);
//            dictionary.Add(name);
//            dictionary.Add(ns);


//            return new MyCustomDataContractSerializer(
//                type,
//                new XmlDictionaryString(dictionary, name, 0),
//                new XmlDictionaryString(dictionary, ns, 1),
//                knownTypes);
//        }

//        public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes)
//        {
//            return new MyCustomDataContractSerializer(
//                type,
//                name,
//                ns,
//                knownTypes);
//        }
//    }


//    public class CustomDataContractFormatAttribute : Attribute, IOperationBehavior
//    {
//        public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters)
//        {
//        }

//        public void ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
//        {
//            ReplaceDataContractSerializerOperationBehavior(description);
//        }

//        public void ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch)
//        {
//            ReplaceDataContractSerializerOperationBehavior(description);
//        }

//        public void Validate(OperationDescription description)
//        {
//        }

//        private static void ReplaceDataContractSerializerOperationBehavior(OperationDescription description)
//        {
//            DataContractSerializerOperationBehavior dcs = description.Behaviors.Find<DataContractSerializerOperationBehavior>();

//            if (dcs != null)
//                description.Behaviors.Remove(dcs);

//            description.Behaviors.Add(new CustomDataContractSerializerOperationBehavior(description));
//        }
//    }
//}
